package com.yonyou.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.JdkIdGenerator;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.dao.PresetWinningDAO;
import com.yonyou.domain.PresetWinning;
import com.yonyou.domain.ResponseEntity;
import com.yonyou.status.CommnonStatus;
import com.yonyou.util.TimeUtil;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping(value = "/presetwinning")
public class PresetWinningController {
	
	@Autowired
	private PresetWinningDAO presetWinningDAO;
	/**
	 * 获取内定中奖人员集合
	 * @param prize_id
	 * @return
	 */
	@RequestMapping(value="/list/{prize_id}",method = RequestMethod.GET)
	@ApiOperation(value = "获取内定中奖人员集合",httpMethod ="GET", response = ResponseEntity.class,notes = "获取内定中奖人员集合")
	public ResponseEntity<PresetWinning> list(@ApiParam(required = true, name = "paramData", value = "奖项ID") @PathVariable String prize_id) {
		ResponseEntity<PresetWinning> responseEntity = new ResponseEntity<PresetWinning>();
		try {
			responseEntity.setData(presetWinningDAO.list(prize_id));
			responseEntity.setCode(0);
			responseEntity.setErrmsg("");
		} catch (Exception e) {
			responseEntity.setCode(1);
			responseEntity.setErrmsg("系统异常");
		}
		return responseEntity;
	}
	
	/**
	 * 保存内定中将人员集合
	 * 
	 * @return
	 */
	@RequestMapping(value="/save",method =RequestMethod.POST)
	@ApiOperation(value = "保存内定中将人员集合",httpMethod ="POST", response = ResponseEntity.class,notes = "保存内定中将人员集合")
	public ResponseEntity<PresetWinning> save(@ApiParam(required = true, name = "paramData", value = "内定中将人员") @RequestBody PresetWinning presetWinning) {
		ResponseEntity<PresetWinning> responseEntity = new ResponseEntity<PresetWinning>();
		try {
			presetWinning.setId(new JdkIdGenerator().generateId().toString());
			presetWinning.setDr(CommnonStatus.SAVSTATUS);
			presetWinning.setTs(TimeUtil.getCurrentTime());
			presetWinningDAO.save(presetWinning);
			responseEntity.setData(presetWinning);
			responseEntity.setCode(0);
			responseEntity.setErrmsg("");
		} catch (Exception e) {
			responseEntity.setCode(1);
			responseEntity.setErrmsg("系统异常");
		}
		return responseEntity;
	}
	
	
}
